#include "stdafx.h"
#include "IPCameraStreamSource.h"
#include "IPCameraStreamReceiver.h"
#include "models.h"

CIPCameraStreamSource::CIPCameraStreamSource(void)
{
	m_int_stream_input_type = STREAM_INPUT_IPCAMERA;
}


CIPCameraStreamSource::~CIPCameraStreamSource(void)
{
	if (m_ptr_input_device)
	{
		if (m_ptr_input_device->self_info)
			delete (DEVICE_IPCAMERA*)m_ptr_input_device->self_info;

		delete m_ptr_input_device;
		m_ptr_input_device = NULL;
	}
}

void CIPCameraStreamSource::StartStreamReceiver()
{
	if (m_ptr_input_device == NULL)
		return;

	if (m_ptr_input_device->self_info == NULL)
		return;

	int int_camera_model = ((DEVICE_IPCAMERA*)m_ptr_input_device->self_info)->model;

	m_bln_isStreamReceiving = TRUE;

	if (m_ptr_stream_receiver)
	{
		m_ptr_stream_receiver->Stop();
		delete m_ptr_stream_receiver;
	}

	char* str_stream_url = new char[1024];
	memset(str_stream_url, 0, 1024);

	switch (int_camera_model)
	{
	case AXIS_Q7401:
		sprintf(str_stream_url, "%s", "");
		break;

	case WANSCAM:
		sprintf(str_stream_url, "%s", "");
		break;

	default:
		break;
	}

	m_ptr_stream_receiver = new CIPCameraStreamReceiver(m_int_stream_id);
	CIPCameraStreamReceiver* ptr_ipcamera_receiver = (CIPCameraStreamReceiver*)m_ptr_stream_receiver;
	ptr_ipcamera_receiver->SetSource(this);
	ptr_ipcamera_receiver->SetRTSPServerURI(str_stream_url);
	//m_ptr_stream_receiver->Start();
}
